#include "BMPWriter.h"

void Snapshot( BYTE * pData, int width, int height, char * filename )

{

	int size = width*height*3; 

	BMPFILEHEADER_T bfh;

	bfh.bfType = 0x4d42; 

	bfh.bfSize = size 

		+ sizeof( BMPFILEHEADER_T ) 

		+ sizeof( BMPINFOHEADER_T ) 

		;

	bfh.bfReserved1 = 0; 

	bfh.bfReserved2 = 0; 

	bfh.bfOffBits = bfh.bfSize - size;


	BMPINFOHEADER_T bih;

	bih.biSize = sizeof(BMPINFOHEADER_T);

	bih.biWidth = width;

	bih.biHeight = height;

	bih.biPlanes = 1;

	bih.biBitCount = 24;

	bih.biCompression = 0;

	bih.biSizeImage = size;

	bih.biXPelsPerMeter = 0;

	bih.biYPelsPerMeter = 0;

	bih.biClrUsed = 0;

	bih.biClrImportant = 0;      

	FILE * fp = fopen( filename,"wb" );

	if( !fp ) return;

	fwrite( &bfh, 1, sizeof(BMPFILEHEADER_T), fp );

	fwrite( &bih, 1, sizeof(BMPINFOHEADER_T), fp );

	fwrite( pData, 1, size, fp );

	fclose( fp );

}